package magic.deckbuilder.mainActivity;

import java.util.ArrayList;

import magic.deckbuilder.Deck;
import magic.deckbuilder.DeckAdapter;
import magic.deckbuilder.MagicDeckDB;
import magic.deckbuilder.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;

public class MainActivity extends Activity {
	
	MagicDeckDB magicDeckDB;
	ListView deckView;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		magicDeckDB = new MagicDeckDB(this);
		
		Deck deck = new Deck("tag", "resume");
		
		magicDeckDB.open();
		
		long id = magicDeckDB.insertDeck(deck);
		
		Toast.makeText(this, "test insert : " + id, Toast.LENGTH_LONG).show();
//		openDB();
//		displayDeck();
//		setListener();
		magicDeckDB.close();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	private void openDB() {
		
		
	}
	
	private void displayDeck() {
		// Display all deck
		ArrayList<Deck> decks = magicDeckDB.getDecks();
		DeckAdapter adapter = new DeckAdapter(this, decks);
		deckView = (ListView)findViewById(R.id.list_deck);
		deckView.setAdapter(adapter);
	}
	
	private void setListener() {
		// Link createDeckButton to CreateDeckActivity
		Button createDeckButton = (Button)findViewById(R.id.add_deck_button);
		//createDeckButton.setOnClickListener(new CreateDeckOnClickListener(this));
		
		// Link deckView to deck modification activity
		//deckView.setOnItemClickListener(new ListDeckOnClickListener(this));		
	}
	
}
